/*DF6KZWeLt9vJbmoGYsUyZhjwpRZcelW5Ht2r7j4UtyNjA3WAUMkmI/Sjj8NB1gX+*/
/*
 * @Descripttion: 主要针对模板meta做的各种公共处理
 * @version:
 * @Author: Chendch
 * @Date: 2021-05-13 13:46:44
 * @LastEditors: Chendch
 * @LastEditTime: 2021-10-29 11:13:46
 */
/**
 * 编辑前当前表单项增补查询条件
 * 填回调方法的话则节点自身去重置模板
 * **/
function handelMetaFormBefore2Condition(props, moduleId, key, queryCondition, call) {
  let meta = props.meta.getMeta();
  meta[moduleId].items.forEach(item => {
      if(item.attrcode == key && item.itemtype=="refer") {
          item.queryCondition = !!item.queryCondition ?
            Object.assign({}, item.queryCondition, queryCondition)
            : queryCondition;
      }
  })
  !call ? props.meta.setMeta(meta) : call(meta);
}

function addQueryConditon(meta, areacode, itemcode, condition) {
  let items = meta[areacode].items || [];
  items.forEach(item => {
      if (item.attrcode == itemcode) {
          item.queryCondition = condition;
      }
  });
}

function deleteQueryCondition(meta, areacode, itemcode) {
  let items = meta[areacode].items || [];
  items.forEach(item => {
      if (item.attrcode == itemcode) {
          if (item.querycondition) {
              delete item['queryCondition']
          }
      }
  });
}

/**
 * 获取模板某一项内容
 * **/
function getMetaItem(meta, moduleId, key) {
  return meta[moduleId].items.find( item => item.attrcode === key) || {}
}

export {
  handelMetaFormBefore2Condition,
  getMetaItem,
  addQueryConditon,
  deleteQueryCondition
}


/*DF6KZWeLt9vJbmoGYsUyZhjwpRZcelW5Ht2r7j4UtyNjA3WAUMkmI/Sjj8NB1gX+*/
